home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / gawk-3.000 / gawk-3 / gawk-3.0.0 / msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-19  |  3.4 KB  |  170 lines

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991-1995 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Programming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  24.  */
  25.  
  26. #include "awk.h"
  27.  
  28. int sourceline = 0;
  29. char *source = NULL;
  30.  
  31. /* prototype needed for ansi / gcc */
  32. void err P((const char *s, const char *emsg, va_list argp));
  33.  
  34. /* err --- print an error message with source line and file and record */
  35.  
  36. /* VARARGS2 */
  37. void
  38. err(s, emsg, argp)
  39. const char *s;
  40. const char *emsg;
  41. va_list argp;
  42. {
  43.     char *file;
  44.  
  45.     (void) fflush(stdout);
  46.     (void) fprintf(stderr, "%s: ", myname);
  47.     if (sourceline != 0) {
  48.         if (source != NULL)
  49.             (void) fprintf(stderr, "%s:", source);
  50.         else
  51.             (void) fprintf(stderr, "cmd. line:");
  52.  
  53.         (void) fprintf(stderr, "%d: ", sourceline);
  54.     }
  55.     if (FNR > 0) {
  56.         file = FILENAME_node->var_value->stptr;
  57.         (void) putc('(', stderr);
  58.         if (file)
  59.             (void) fprintf(stderr, "FILENAME=%s ", file);
  60.         (void) fprintf(stderr, "FNR=%ld) ", FNR);
  61.     }
  62.     (void) fprintf(stderr, s);
  63.     vfprintf(stderr, emsg, argp);
  64.     (void) fprintf(stderr, "\n");
  65.     (void) fflush(stderr);
  66. }
  67.  
  68. /* msg --- take a varargs error message and print it */
  69.  
  70. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  71. void
  72. msg(char *mesg, ...)
  73. #else
  74. /*VARARGS0*/
  75. void
  76. msg(va_alist)
  77. va_dcl
  78. #endif
  79. {
  80.     va_list args;
  81. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  82.     va_start(args, mesg);
  83. #else
  84.     char *mesg;
  85.  
  86.     va_start(args);
  87.     mesg = va_arg(args, char *);
  88. #endif
  89.     err("", mesg, args);
  90.     va_end(args);
  91. }
  92.  
  93. /* warning --- print a warning message */
  94.  
  95. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  96. void
  97. warning(char *mesg, ...)
  98. #else
  99. /*VARARGS0*/
  100. void
  101. warning(va_alist)
  102. va_dcl
  103. #endif
  104. {
  105.     va_list args;
  106. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  107.     va_start(args, mesg);
  108. #else
  109.     char *mesg;
  110.  
  111.     va_start(args);
  112.     mesg = va_arg(args, char *);
  113. #endif
  114.     err("warning: ", mesg, args);
  115.     va_end(args);
  116. }
  117.  
  118. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  119. void
  120. error(char *mesg, ...)
  121. #else
  122. /*VARARGS0*/
  123. void
  124. error(va_alist)
  125. va_dcl
  126. #endif
  127. {
  128.     va_list args;
  129. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  130.     va_start(args, mesg);
  131. #else
  132.     char *mesg;
  133.  
  134.     va_start(args);
  135.     mesg = va_arg(args, char *);
  136. #endif
  137.     err("error: ", mesg, args);
  138.     va_end(args);
  139. }
  140.  
  141. /* fatal --- print an error message and die */
  142.  
  143. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  144. void
  145. fatal(char *mesg, ...)
  146. #else
  147. /*VARARGS0*/
  148. void
  149. fatal(va_alist)
  150. va_dcl
  151. #endif
  152. {
  153.     va_list args;
  154. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  155.     va_start(args, mesg);
  156. #else
  157.     char *mesg;
  158.  
  159.     va_start(args);
  160.     mesg = va_arg(args, char *);
  161. #endif
  162.     err("fatal: ", mesg, args);
  163.     va_end(args);
  164. #ifdef DEBUG
  165.     abort();
  166. #endif
  167.     exit(2);
  168. }
  169.  
  170.